<template>
  <div>
    <MainPage :data="showList" @search="search" @newshow="newshow"></MainPage>
    <ListPage v-if="edit" @close="close" :obj="good"></ListPage>
  </div>
</template>

<script>
import MainPage from "./components/MainPage.vue";
import ListPage from "./components/ListPage.vue";
export default {
  components: { MainPage, ListPage },
  data() {
    return {
      edit: false,
      good: "",
      record: "",
      records: [
        {
          date: "2022-01-01",
          doctor: "张三",
          diagnosis: "感冒",
          prescription: "感冒药",
        },
        {
          date: "2022-02-01",
          doctor: "李四",
          diagnosis: "头疼",
          prescription: "止疼药",
        },
        {
          date: "2022-03-01",
          doctor: "王五",
          diagnosis: "腰痛",
          prescription: "止痛贴",
        },
      ],
    };
  },
  methods: {
    close() {
      this.edit = false;
    },
    search(msg) {
      this.record = msg;
    },
    newshow(msg) {
      this.good = msg;
      this.edit = true;
    },
  },
  computed: {
    showList() {
      if (this.record !== "") {
        return this.records.filter((item) => item.doctor === this.record);
      }
      return this.records;
    },
  },
};
</script>

<style></style>
